TARGET = riselib

BUILD_DIR := BUILD

C_SOURCES += $(wildcard *.c )

OBJECTS += $(patsubst %.c,$(BUILD_DIR)/%.o,$(C_SOURCES))

CC = gcc
CXX = g++

MYFLAGS += -Wall
MYFLAGS += -g
MYFLAGS += -D DEBUG
CFLAGS += -std=c99

ifeq ($(shell echo $$OS),$$OS)
	MAKEDIR = if not exist "$(1)" mkdir "$(1)"
	RM = rmdir /S /Q "$(1)"
else
	MAKEDIR = '$(SHELL)' -c "mkdir -p \"$(1)\""
	RM = '$(SHELL)' -c "rm -rf \"$(1)\""
endif

all: $(TARGET)
$(TARGET): $(OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $^  $(MYFLAGS)
$(OBJECTS): $(BUILD_DIR)/%.o: %.c
	+@$(call MAKEDIR,$(dir $@))
	$(CC) $(CFLAGS)  -c $^ -o $@  $(MYFLAGS) $(INCLUDE_DIRS)

clean:
	@rm -rf $(TARGET)
	@rm -rf *.stackdump
	@rm -rf $(BUILD_DIR)
